package com.example.app13_sqlite.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.app13_sqlite.R;
import com.example.app13_sqlite.entity.BlackNumber;

import java.util.List;

public class BlackNumberAdapter extends BaseAdapter {

    private Context context;

    private List<BlackNumber> blackNumberList;

    public BlackNumberAdapter(Context context, List<BlackNumber> blackNumberList) {
        this.context = context;
        this.blackNumberList = blackNumberList;
    }

    @Override
    public int getCount() {
        return blackNumberList.isEmpty() ? 0 : blackNumberList.size();
    }

    @Override
    public Object getItem(int position) {
        return blackNumberList.isEmpty() ? new BlackNumber() : blackNumberList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_black_number, null);
        }

        BlackNumber blackNumber = blackNumberList.get(position);
        TextView tvNumber = convertView.findViewById(R.id.tv_number);
        tvNumber.setText(blackNumber.getNumber());

        return convertView;
    }
}
